﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;
using CommonUtility;
using System.Web.Script.Serialization;
namespace WebApplication
{
    public partial class FunctionInf : BasePage
    {
        const string FunID = "FA03";
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Common.ToString(Request["Action"]);
            switch (action)
            {
                case "GetList":
                    Response.Write(LoadList());
                    Response.End();
                    break;
                case "Save":
                    Response.Write(Save());
                    Response.End();
                    break;
                case "Process":
                    Response.Write(Process(Common.ToString(Request["type"])));
                    Response.End();
                    break;
                case "LoadFunItem":
                    Response.Write(LoadFunItem());
                    Response.End();
                    break;
            }
            if (!IsPostBack && string.IsNullOrEmpty(action))
            {
                bllPermission Perm = new bllPermission(oUser.UserID, FunID);
                hdPermission.Value = new JavaScriptSerializer().Serialize(Perm);
            }
        }

        /// <summary>
        /// 获取明细
        /// </summary>
        /// <returns></returns>
        private string LoadList()
        {
            string result = "";
            result = new bllFunction().GetFunInf(Common.ConvertSql(Common.ToString(Request["FunID"])), Common.ConvertSql(Common.ToString(Request["FunDesc"])), oUser);
            return result;
        }

        private string LoadFunItem()
        {
            return new bllFunction().LoadFunItem(oUser);
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        private string Save()
        {
            string result = string.Empty;
            var rid = Common.ToString(Request["RID"]);
            var funID = Common.ToString(Request["FunID"]);
            var funDesc = Common.ToString(Request["FunDesc"]);
            var flag= Common.ToString(Request["Flag"]);
            var strActID = Common.ToString(Request["ActID"]);
            result = new BLL.bllFunction().Save(FunID, rid, funID, funDesc, flag, strActID, oUser);
            return result;
        }

        /// <summary>
        /// 设置Falg
        /// </summary>
        /// <param name="_status">A or I</param>
        /// <returns></returns>
        private string Process(string flag)
        {
            string res = string.Empty;
            res = new bllFunction().Process(FunID, Common.ConvertSql(Common.ToString(Request["rids"])), flag, oUser);

            return res;
        }
    }
}